package com.chukun.flink.stream.operator.base;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author chukun
 * @version 1.0.0
 * @description map 操作符
 * @createTime 2022年05月10日 00:06:00
 */
public class MapOperator {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStream<Long> streamSource = env.fromSequence(1, 5);

        DataStream<Tuple2<Long, Integer>> mapStream = streamSource.map(new MapFunction<Long, Tuple2<Long, Integer>>() {
            @Override
            public Tuple2<Long, Integer> map(Long aLong) throws Exception {
                return new Tuple2<>(aLong * 100, aLong.hashCode());
            }
        });

        mapStream.print("输出结果");

        // 触发程序执行
        env.execute();
    }
}
